home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / gray image 2.1 / window.h < prev    next >
Text File  |  1995-06-11  |  3KB  |  106 lines

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *
  5.  *            Simple Window Class
  6.  *        
  7.  *
  8.  ***********************************************************************
  9.  */
  10.  
  11. /*
  12.  *----------------------------------------------------------------------
  13.  *                Service functions
  14.  */
  15.  
  16. class IMAGE;                // Opaque class
  17.  
  18. class ScreenRect : public Rect
  19. {
  20. public:
  21.   ScreenRect(const Rect& rect) : Rect(rect) {}
  22.   ScreenRect(const IMAGE& image);
  23.   ScreenRect(const rowcol& heightwidth);
  24.                     // Create a rectangle of given height/width
  25.                     // positioned at a given point
  26.   ScreenRect(const rowcol& origin, const rowcol& heightwidth);
  27.   ScreenRect& operator += (const int offset);
  28.   operator Rect * (void)     { return this; }
  29.   void print(const char * title = "") const;
  30. };
  31.  
  32.  
  33. /*
  34.  *----------------------------------------------------------------------
  35.  *    A generic simple window that can be dragged around the screen
  36.  *        and closed by clicking a "go-away" button
  37.  * No other events are handled, redefine the event handler if necessary.
  38.  */
  39.  
  40. class ScreenWindow
  41. {
  42.   WindowPtr this_window;
  43.     
  44.   Boolean handle_mouse_down(const EventRecord& the_event);
  45.   virtual Boolean handle_key_down(const EventRecord& the_event);    // Handles key_down & auto_key events
  46.   virtual Boolean handle_null_event(const long event_time);
  47.   void drag(Point where) { DragWindow(this_window,where,&qd.screenBits.bounds); }
  48.   void activate(const Boolean go_active);
  49.   void update(void);
  50.   virtual void draw(void) = 0;            // It is this function that really draws smth
  51.     
  52. protected:
  53.   WindowPtr our_window(void) const     { return this_window; }
  54.     
  55. public:
  56.   ScreenWindow(ScreenRect rect, const char * title);
  57.   ScreenWindow(const short resource_id);        // Create a window from a resource template
  58.   ~ScreenWindow(void);
  59.   void handle(void);
  60.   void refresh(void);
  61. };
  62.  
  63. /*
  64.  *----------------------------------------------------------------------
  65.  *        A simple window with an offscreen window buffer
  66.  */
  67.  
  68. class OffScreenWindow : public ScreenWindow
  69. {
  70.   friend class SetOffscreenWorld;
  71.   GWorldPtr graf_world;                // (Offscreen) graphical world that contains the picture
  72.  
  73.   void activate_palette(void);            // Activate palette for the window
  74.   void draw(void);                // Draw the offscreen buffer on screen
  75.  
  76. protected:
  77.   PixMapHandle pixmap;                // Pixmap for the offscreen world
  78.   int _height;                        // Dimensions of the pixmap (precomputed for
  79.   int _width;                        // easy reference
  80.   int _bytes_per_row;                    // Note, bytes_per_row >= width (and generally, not equal)
  81.     
  82. public:
  83.   OffScreenWindow(ScreenRect rect, const char * title, const short clut_id=0);
  84.   ~OffScreenWindow(void);
  85.  
  86.   PixMapHandle get_pixmap(void) const        { return pixmap; }
  87.         
  88.   ScreenRect q_bounds(void) const;    // Bounding rect of the grafworld
  89.   int height(void) const            { return _height; }         
  90.   int width(void) const                { return _width; }         
  91.   int bytes_per_row(void) const            { return _bytes_per_row; }         
  92. };
  93.  
  94.                 // Make it easy setting and resetting
  95.                 // the current window
  96. class SetOffscreenWorld
  97. {
  98.   GrafPtr old_port;
  99. public:
  100.                     // Switch to an off-screen grafworld
  101.   SetOffscreenWorld(const OffScreenWindow& offscreen_window)     
  102.     { GetPort(&old_port); SetPort((GrafPtr)offscreen_window.graf_world); }
  103.                     // Restore the original grafworld
  104.  ~SetOffscreenWorld(void) { SetPort(old_port); }
  105. };
  106.